package controlador;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Random;
import java.util.Vector;

import modelo.dto.Nivel;
import modelo.dao.NivelDao;
import vista.vMastermind;

public class cMastermind implements ActionListener, MouseListener {
	private vMastermind vmastermind;
	private Nivel niveles=new Nivel();
	   
	  public cMastermind(Nivel nivel)
	   {
			super();
			niveles=nivel;
			this.vmastermind = new vMastermind(niveles);
			this.vmastermind.setLocationRelativeTo(null);
			this.vmastermind.setVisible(true);	
			vmastermind.agregarListener(this);
			vmastermind.agregarMouseListener(this);
	   }

	@Override
	public void actionPerformed(ActionEvent e) {
		String accion=e.getActionCommand();
		
		if(accion.equals("Comprobar")){
			vmastermind.PresionarComprobar();
		}
		
		if(accion.equals("Salir")){
			new cNivel();
			vmastermind.dispose();
		}
		
		if(accion.equals("Nuevo Juego")){
		vmastermind.nuevojuego(ExtraerClave());
		}
		if(accion=="Puntuacion")
		{
			new cListaPuntuacion();
			vmastermind.dispose();
		}
		if(accion=="Iniciar"){
			vmastermind.Iniciar();
		}
	}

	@Override
	public void mouseClicked(MouseEvent me) {
	}

	@Override
	public void mouseEntered(MouseEvent me) {
	}

	@Override
	public void mouseExited(MouseEvent me) {
	}

	@Override
	public void mousePressed(MouseEvent me) {
	vmastermind.PresionarPelota(me);
	}

	@Override
	public void mouseReleased(MouseEvent me) {
	}
	
	public Nivel ExtraerClave()
	{
		NivelDao niveldao=new NivelDao();
		Vector<Nivel> nivel=new Vector<Nivel>();
		nivel=niveldao.ExtraerNivel(niveles.getDificultad());
		Random random = new Random();
		int i = random.nextInt(nivel.size());
		return nivel.get(i);
	}
}
